/* 
 * Copyright (c), nFractals Ltd. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.parade;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import org.parade.distributed.Id;
import org.parade.distributed.Queue;
import org.parade.driver.Driver;

public class Parade {
	private static Driver driver = null;
	
	/**
	 * Class name for driver
	 * 
	 * @param className	 eg) org.parade.driver.hazelcast.Driver
	 * @return
	 * @throws ClassNotFoundException 
	 * @throws NoSuchMethodException 
	 * @throws SecurityException 
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 * @throws IllegalArgumentException 
	 */
	public static Driver loadDriver(String className, @SuppressWarnings("rawtypes") Class [] types, Object [] params) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException{
		Class<?> cls = Thread.currentThread().getContextClassLoader().loadClass(className);
		Constructor<?> constructor = cls.getConstructor(types);
		Driver driver =  (Driver) constructor.newInstance(params);
		driver.startThreadExecutionService();
		return driver;
	}
	
	/**
	 * Set singleton driver
	 * 
	 * @param driver	driver to set
	 */
	public static void setDriver(Driver driver){
		Parade.driver = driver;
	}
	
	/**
	 * Get singleton driver
	 * Driver must be loaded before call this method by setDriver
	 * 
	 * @return	driver
	 */
	public static Driver getDriver(){
		return driver;
	}


	
}
